package com.linkage.educloud.ah.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.bean.StudyTypeBean;

import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/20.
 */

public class SubjectTypeAdapter extends android.widget.BaseAdapter {

    private Context mContext;
    private List<StudyTypeBean> mList;
    private int mType = -1;//-1为grade  其他为subject
    private int SelectPosition = 0;

    public SubjectTypeAdapter(Context context, List<StudyTypeBean> list, int type) {
        this.mContext = context;
        this.mList = list;
        this.mType = type;
    }

    public void changeSelected(int positon) {
        SelectPosition = positon;
        notifyDataSetChanged();
    }

    public void changeBottom(int positon) {
        SelectPosition = 0;
        mType = positon;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        return mList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int arg0, View view, ViewGroup arg2) {
        final ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_subject_type, null);
            holder = new ViewHolder();
            holder.search_text = view.findViewById(R.id.item_subject_type_text);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        StudyTypeBean bean = mList.get(arg0);
        if (mType == -1) {
            holder.search_text.setText(bean.getName());
        } else {
            holder.search_text.setText(bean.getSubjects().get(mType).getName());
        }

        if (SelectPosition == arg0) {
            if (mType == -1) {
                holder.search_text.setTextColor(Color.parseColor("#2fd3e6"));
            } else {
                holder.search_text.setTextColor(Color.parseColor("#59e7a9"));
            }
        } else {
            holder.search_text.setTextColor(Color.parseColor("#000000"));
        }
        return view;
    }

    class ViewHolder {
        private TextView search_text;
    }
}
